package com.stx.blog.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.stx.blog.service.ArticleService;
import com.stx.blog.util.BlogUtil;
import com.stx.blog.vo.BcategoryVo;
import com.stx.blog.vo.UserVo;

public class BcategoryAction extends ActionSupport {

	private UserVo uv;
	private BcategoryVo bv;
	private String add;
	private ArticleService as;
    private BlogUtil   bu;
    private List<BcategoryVo> list=new ArrayList<BcategoryVo>();
  
    public String getAdd() {
		return add;
	}

	public void setAdd(String add) {
		this.add = add;
	}

	public BcategoryVo getBv() {
		return bv;
	}

	public void setBv(BcategoryVo bv) {
		this.bv = bv;
	}

	public List<BcategoryVo> getList() {
		return list;
	}

	public void setList(List<BcategoryVo> list) {
		this.list = list;
	}

	
	public ArticleService getAs() {
		return as;
	}

	public void setAs(ArticleService as) {
		this.as = as;
	}

	public BlogUtil getBu() {
		return bu;
	}

	public void setBu(BlogUtil bu) {
		this.bu = bu;
	}

	public UserVo getUv() {
		return uv;
	}

	public void setUv(UserVo uv) {
		this.uv = uv;
	}
	
	public String findBcategory(){
		uv=(UserVo) ServletActionContext.getRequest().getSession().getAttribute("user");
		list=as.findBcategory(uv);
		return "findbcategory";
	}
	public String addBcategory(){
		if(!"".equals(add)&&add.length()<10){
		bv=new BcategoryVo();
		bv.setCname(add);
		bv.setCreatetime(new Date());
		uv=(UserVo) ServletActionContext.getRequest().getSession().getAttribute("user");
		bv.setBuid(uv.getBuid());
		as.addBcategory(bv);
		return "addok";
		}else{
			addActionError("字符长度小于10且不能为空！");
			return "input";
		}
	}
	
	public String delBcategory(){
		
		as.delBcategory(bv);
		return "delok";
	}
	
}
